<?php
/**
 * 
 * @author tangbl
 *
 */
class ContentAction extends CommonAction{
	
	private $_module_id; //模型Id
	private $_lang;
	
	//初始化
	public function _initialize() {
		parent::_initialize();
		parent::_initmenu();
		
		/*
		$mods   = F('module');
		$mods[] = "Public";
		$name   = ucfirst(strtolower(MODULE_NAME));
		if(!in_array($name,$mods)){
			$this->error(L('cfg_form_module_noexsits'));
		}
		*/
		
		
		$this->_lang = getLang();
		import('ORG.Module.ThinkFrom');
		$module_id = $this->_get('module_id',"intval","");
		if($module_id){
			$this->_module_id = $module_id;
		}else{
			$Module = M('Module');
			$data = $Module->where('module_name="'.strtolower(MODULE_NAME).'"')->find();
			$this->_module_id = @$data['id'];
		}
		
		if(empty($this->_module_id)){
			$this->assign("jumpUrl",U('/Index/index'));   
			$this->error(L('cfg_module_noexist'));
		}
	}
	
	public function add(){
		$module_id = $this->_module_id;
		
		//查询模型信息
		$Module = M('Module');
		$data   = $Module->find($module_id);
		$pid    = $data['module_pid'];
		$type   = $data['module_type'];
		$parent_name = $data['module_name'] ;
		
		if($type == 2 && $pid){				
			$parent_data    = $Module->find($pid);
			$parent_name    = $parent_data['module_name'];
			$parent_title   = json_decode($parent_data['title'],true);
			$parent_title   = $parent_title[$this->_lang];
		}
		
		if(IS_POST){
			//所属模型
			$arr['cmodule'] = $parent_name ;
			$arr['addtime'] = time() ;
			$arr['addid']   = session(C('USER_AUTH_KEY')) ;
			
			$filed = M('ModuleFiled');
			if($type == 2 && $pid){
				
				//查模型对应字段
				$filed_data = $filed->where('module_id='.$module_id.'')->order('order_num DESC')->select();
				//当模型字段是图片、上传文件时
				foreach($filed_data as $v){
					if($v['filed_type']=='signle'){
						$eimage["single"][] = $v['filed_name'];
					}
					if($v['filed_type']=='atlas'){
						$eimage["atlas"][] = $v['filed_name'];
					}
				}
				$this->content_add($parent_name,$eimage,$arr);
				
				$parent_data    = $Module->find($pid);
				$module_id      = $parent_data['id'];
				$parent_name    = $parent_data['module_name'];
			}
			
			//查模型对应字段
			$filed_data = $filed->where('module_id='.$module_id.'')->order('order_num DESC')->select();
			//当模型字段是图片、上传文件时
			foreach($filed_data as $v){
				if($v['filed_type']=='signle'){
					$pimage["single"][] = $v['filed_name'];		
				}
				if($v['filed_type']=='atlas'){
					$pimage["atlas"][] = $v['filed_name'];
				}
			}
			$param = array(
				"upload" => $pimage,
				"reply"  => false,
				"arr"    => $arr
			);
			
			parent::do_add($parent_name,$param);
		
		} else {
			$Module    = M('Module');
			$Module_data = $Module->where('id='.$module_id.'')->find();
			
			if($Module_data['module_type']==2){
				$wid = $Module_data['module_pid'].','.$module_id;
				$where = "module_id IN ($wid)";
			}else{
				$where = "module_id =".$module_id;
			}
			
			
			$Module_tab = M('Module_tab');
			$Module_tab_data = $Module_tab->where($where)->select();
			$Module_filed = M('Module_filed');
			$Module_filed_data = $Module_filed->where($where)->order('order_num DESC')->select();
			
			$Module_title = json_decode($Module_data['title'],true);
			$Module_title = $Module_title[$this->_lang];
			
			//组装面包屑导航
			if($type == 2 && $pid){
				$position = '<a href="?s=/'.ucfirst($parent_name).'/index/module_id/'.$pid.'">'.L('cfg_list_itf_prefix_manage').$parent_title.'</a>';
				$position .= ' <span class="icon-angle-right"></span> '.'<a href="?s=/'.ucfirst($parent_name).'/index/module_id/'.$module_id.'">'.L('cfg_list_itf_prefix_manage').$Module_title.'</a>';
			}else{
				$position = '<a href="?s=/'.ucfirst($name).'/index/module_id/'.$module_id.'">'.L('cfg_list_itf_prefix_manage').$Module_title.'</a>';
			}
			$position .= ' <span class="icon-angle-right"></span> '.L('cfg_list_itf_prefix_add').$Module_title;
			
			//表单参数
			$form = array(
				'module' => $Module_data['module_name'],
				'action' => __URL__.'/add/module_id/'.$module_id,
				'hidden' => array(
					'solevar' => create_id(),
					'id' => '',
					'addtime' => time(),
				)	
			);
			
			//Tab参数
			if($Module_tab_data){
				foreach($Module_tab_data as $k=>$v){
					$form['tab'][$k]['tab_name'] =  json_decode($v['tab_name'],true);
					$form['tab'][$k]['tab_id'] = $v['id'];
					$form['tab'][$k]['tab_type'] = $v['tab_type'];
				}
			}
			
			//字段参数
			if($Module_filed_data){
				foreach($Module_filed_data as $k=>$v){
					$filed_attr = json_decode($v['filed_attr'],true);
					$valid_attr = json_decode($v['valid_attr'],true);
					foreach($valid_attr['tis'] as $vk=>$vv){
						$valid_attr['tis'][$vk] =  json_decode($vv,true);
					}
					
					$form['ele'][$k]['file_base']['filed_title'] = json_decode($v['filed_title'],true);
					$form['ele'][$k]['file_base']['css_class'] = $v['css_class'];
					$form['ele'][$k]['file_base']['filed_type'] = $v['filed_type'];
					$form['ele'][$k]['file_base']['tab_id'] = $v['tab_id'];
					$form['ele'][$k]['file_base']['filed_name'] = $v['filed_name'];
					
					$form['ele'][$k]['filed_attr'] = $filed_attr;
					$form['ele'][$k]['valid_attr'] = $valid_attr;
				}
			}

			$form_obj = new ThinkForm($form);
			$html_form = $form_obj->createForm();
			
			$this->assign("Module_title",$Module_title);
			$this->assign("html_form",$html_form);
			$this->assign("position",$position);
			$this->display("Content:add");
		}
	}
	
	public function edit(){
		$id = I('param.id',0,'');//获取id值
		$module_id = $this->_module_id;
		
		//查询模型信息
		$Module = M('Module');
		$data   = $Module->find($module_id);
		$pid    = $data['module_pid'];
		$type   = $data['module_type'];
		$parent_name = $data['module_name'] ;
		
		if($type == 2 && $pid){				
			$parent_data    = $Module->find($pid);
			$parent_name    = $parent_data['module_name'];
			$parent_title   = json_decode($parent_data['title'],true);
			$parent_title   = $parent_title[$this->_lang];
		}
		
		if(IS_POST){			
			//主键
			$map['solevar'] = $this->_param("solevar");
			$arr['id'] = M("$parent_name")->where($map)->getField("id");
			
			$filed = M('ModuleFiled');
			if($type == 2 && $pid){				
				//查模型对应字段
				$filed_data = $filed->where('module_id='.$module_id.'')->order('order_num DESC')->select();
				//当模型字段是图片、上传文件时
				foreach($filed_data as $v){
					if($v['filed_type']=='signle'){
						$eimage["single"][] = $v['filed_name'];
					}
					if($v['filed_type']=='atlas'){
						$eimage["atlas"][] = $v['filed_name'];
					}
				}
				$this->content_edit($parent_name,$eimage,$arr);
				
				$parent_data    = $Module->find($pid);
				$module_id      = $parent_data['id'];
				$parent_name    = $parent_data['module_name'];
				$arr['id'] = M("$parent_name")->where($map)->getField("id");
			}
			
			//查模型对应字段
			$filed_data = $filed->where('module_id='.$module_id.'')->order('order_num DESC')->select();
			//当模型字段是图片、上传文件时
			foreach($filed_data as $v){
				if($v['filed_type']=='signle'){
					$pimage["single"][] = $v['filed_name'];		
				}
				if($v['filed_type']=='atlas'){
					$pimage["atlas"][] = $v['filed_name'];
				}
			}
			$param = array(
				"upload" => $pimage,
				"reply"  => false,
				"arr"    => $arr
			);
			
			parent::do_edit($parent_name,$param);
			
		} else {
			$Module    = M('Module');
			$Module_data = $Module->find($module_id);
			if($Module_data['module_type']==2){
				$wid = $Module_data['module_pid'].','.$module_id;
				$where = "module_id IN ($wid)";
				
				//查找父模型名称
				$parent_data    = $Module->find($Module_data['module_pid']);
				$parent_name    = $parent_data['module_name'];
				$modi_data_main = M($parent_name)->find($id);
				$modi_data_from = M($Module_data['module_name'])->where('solevar=\''.$modi_data_main['solevar'].'\'')->find();
				
				$modi_data = $modi_data_main;
				foreach($modi_data_from as $k=>$v){
					if($k!='id' && $k!='solevar' && $k!='addid' && $k!='addtime' && $k!='cmodule'){
						$modi_data[$k] = $v;
					}
				}
			}else{
				$where = "module_id =".$module_id;
				$modi_data = M(MODULE_NAME)->find($id);
			}
			
			$Module_tab = M('Module_tab');
			$Module_tab_data = $Module_tab->where($where)->select();
			$Module_filed = M('Module_filed');
			$Module_filed_data = $Module_filed->where($where)->order('order_num DESC')->select();
			
			$Module_title = json_decode($Module_data['title'],true);
			$Module_title = $Module_title[$this->_lang];
			
			//组装面包屑导航
			if($type == 2 && $pid){
				$position = '<a href="?s=/'.ucfirst($parent_name).'/index/module_id/'.$pid.'">'.L('cfg_list_itf_prefix_manage').$parent_title.'</a>';
				$position .= ' <span class="icon-angle-right"></span> '.'<a href="?s=/'.ucfirst($parent_name).'/index/module_id/'.$module_id.'">'.L('cfg_list_itf_prefix_manage').$Module_title.'</a>';
			}else{
				$position = '<a href="?s=/'.ucfirst($name).'/index/module_id/'.$module_id.'">'.L('cfg_list_itf_prefix_manage').$Module_title.'</a>';
			}
			$position .= ' <span class="icon-angle-right"></span> '.L('cfg_list_itf_prefix_modify').$Module_title;
			
			
			//表单参数
			$form = array(
				'module' => $Module_data['module_name'],
				'action' => __URL__.'/edit/module_id/'.$module_id,
				'hidden' => array(
					'solevar' => $modi_data['solevar'],
					'id' => $modi_data['id'],
					'addtime' => time(),
				)
			);
			
			//Tab参数
			if($Module_tab_data){
				foreach($Module_tab_data as $k=>$v){
					$form['tab'][$k]['tab_name'] =  json_decode($v['tab_name'],true);
					$form['tab'][$k]['tab_id'] = $v['id'];
					$form['tab'][$k]['tab_type'] = $v['tab_type'];
				}
			}
			
			//字段参数
			if($Module_filed_data){
				foreach($Module_filed_data as $k=>$v){
					$filed_attr = json_decode($v['filed_attr'],true);
					$valid_attr = json_decode($v['valid_attr'],true);
					foreach($valid_attr['tis'] as $vk=>$vv){
						$valid_attr['tis'][$vk] =  json_decode($vv,true);
					}
					
					$form['ele'][$k]['file_base']['filed_title'] = json_decode($v['filed_title'],true);
					$form['ele'][$k]['file_base']['css_class'] = $v['css_class'];
					$form['ele'][$k]['file_base']['filed_type'] = $v['filed_type'];
					$form['ele'][$k]['file_base']['tab_id'] = $v['tab_id'];
					$form['ele'][$k]['file_base']['filed_name'] = $v['filed_name'];
					
					$form['ele'][$k]['filed_attr'] = $filed_attr;
					$form['ele'][$k]['filed_attr']['default'] = $modi_data[$v['filed_name']];
					$form['ele'][$k]['valid_attr'] = $valid_attr;
					
					if($form['ele'][$k]['file_base']['filed_type'] == 'signle' || $form['ele'][$k]['file_base']['filed_type'] == 'atlas' || $form['ele'][$k]['file_base']['filed_type'] == 'file' || $form['ele'][$k]['file_base']['filed_type'] == 'files'){
						$str = '';
						if($form['ele'][$k]['file_base']['filed_type'] == 'signle'){
							$single = find_thumb($modi_data['solevar'],$v['filed_name'],MODULE_NAME);
							$str .= '<dl>';
							$str .= '<dt>';
							$str .= '<img src="'.UPLOAD_URL.$single['fileurl'].'">';
							$str .= '</dt>';
							$str .= '<dd class="picname">';
							$str .= '<input type="text" name="'.$v['filed_name'].'_title[]" value="'.$single['c_title'].'">';
							$str .= '<input type="hidden" name="'.$v['filed_name'].'_url[]" ';
							$str .= 'value="'.UPLOAD_URL.$single['fileurl'].'">';
							$str .= '</dd>';
							$str .= '<dd class="pictool">';
							$str .= '<span class="pdel">';
							$str .= '<i class="icon-remove-sign"></i>';
							$str .= '</span>';
							$str .= '<span class="pzoom">';
							$str .= '<i class="icon-cut"></i>';
							$str .= '</span>';
							$str .= '<span class="pshow">';
							$str .= '<i class="icon-eye-open"></i>';
							$str .= '</span>';
							$str .= '</dd>';
							$str .= '</dl>';
						}
						
						if($form['ele'][$k]['file_base']['filed_type'] == 'atlas'){
							$atlas = find_album($modi_data['solevar'],$v['filed_name'],MODULE_NAME);
							foreach($atlas as $v){
								$str .= '<dl>';
								$str .= '<dt>';
								$str .= '<img src="'.UPLOAD_URL.$v['fileurl'].'">';
								$str .= '</dt>';
								$str .= '<dd class="picname">';
								$str .= '<input type="text" name="'.$v['filed_name'].'_title[]" value="'.$v['c_title'].'">';
								$str .= '<input type="hidden" name="'.$v['filed_name'].'_url[]" ';
								$str .= 'value="'.UPLOAD_URL.$v['fileurl'].'">';
								$str .= '</dd>';
								$str .= '<dd class="pictool">';
								$str .= '<span class="pdel">';
								$str .= '<i class="icon-remove-sign"></i>';
								$str .= '</span>';
								$str .= '<span class="pzoom">';
								$str .= '<i class="icon-cut"></i>';
								$str .= '</span>';
								$str .= '<span class="pshow">';
								$str .= '<i class="icon-eye-open"></i>';
								$str .= '</span>';
								$str .= '</dd>';
								$str .= '</dl>';
							}
						}
						$form['ele'][$k]['filed_attr']['default'] = $str;						
					}
				}
			}
			
			$form_obj = new ThinkForm($form);
			$html_form = $form_obj->createForm();
			
			$this->assign("Module_title",$Module_title);
			$this->assign("position",$position);
			$this->assign("html_form",$html_form);
			$this->display("Content:edit");
		}
	}
	
	public function del(){
		
		parent::do_del(MODULE_NAME);
	}
	
	public function index(){
		if(IS_AJAX){
			import('ORG.Util.Page');// 导入分页类
		
			$module_id = $this->_module_id;
			$Module = M('Module');
			$data   = $Module->find($module_id);
			$name    = $data['module_name'];
			$pid    = $data['module_pid'];
			$type    = $data['module_type'];
			
			if($type == 2 && $pid){
				$data = $Module->find($pid);
			}else{
				$data = $Module->find($module_id);
			}
			$list_attr = json_decode($data['list_attr'],true);
			
			$data      = M(MODULE_NAME);
			
			$orderDesc = $this->_get("orderDirection","trim","desc");;
			$orderName = $this->_get("orderName","trim","addtime");
			$pageNum   = $this->_get("pageNum","intval",C('web_admin_pagenum'));
			
			$map       = unescape($this->_get("where"));
	
			if($type == 2 && $pid){
				$map   = "1=1 AND cmodule='".strtolower($name)."' ".$map;
			}else{
				$map   = "1=1 ".$map;
			}
			$count     = $data->where($map)->count();
			$Page      = new Page($count);// 实例化分页类 传入总记录数
			$nowPage   = isset($_GET['p'])?$_GET['p']:1;
			$show      = $Page->show();// 分页显示输出
			$list      = $data->where($map)->order($orderName.' '.$orderDesc)
							  ->page($nowPage.','.$pageNum)->select();
			$totalPage = ceil($count/$pageNum);
			C('web_admin_pagenum',$pageNum);
			
			//exit($data->getlastSql());
			
			$jsonData  = array('page'=>$nowPage,'total'=>$count,'rows'=>array(),'totalPage'=>$totalPage);
	
			foreach($list AS $row){
				//查找模型id
				$Module = M('Module');
				$data_module  = $Module->where('module_name="'.$row['cmodule'].'"')->find();
				$edit = '?s='.MODULE_NAME."/edit/module_id/".$data_module['id'].'/id/'.$row['id'];
				$entry = array('id'=>$row['id'],
					'cell'=>array(
						'id'       => $row['id'],
						'addtime'  => date('Y-m-d',$row['addtime']),
						'deal'=>'<a href="'.$edit.'" class="btn blue icn-only" title="'.L('cfg_list_itf_btn_modify').'"><i class="icon-edit"></i></a>  
								 <a class="btn red icn-only delAlone" title="'.L('cfg_list_itf_btn_delete').'" data-id="'.$row['id'].'"><i class="icon-remove"></i></a> '
					),
				);
				foreach($list_attr['colModel']['name'] as $k=>$v){
					$_Module = M('Module');
					$_module_id = $_Module->where('module_name="'.strtolower(MODULE_NAME).'"')->getField('id');
					$Module_filed = M('Module_filed');		
					$_data_filed  = $Module_filed->where('module_id='.$_module_id.' AND filed_name="'.$v.'"')->field('filed_type,filed_attr')->find();
					$_data_filed['filed_attr'] = json_decode($_data_filed['filed_attr'],true);
					
					//下拉、单选、复选的显示应该是value对应的text
					if($_data_filed['filed_type']=='select' || $_data_filed['filed_type']=='radio' ||$_data_filed['filed_type']=='checkbox'){
						$options = $_data_filed['filed_attr']['options'];
						$options_arr = explode("\r\n",$options);		
						foreach($options_arr as $ok=>$ov){
							if(strpos($ov,$row[$v])!==false){
								$entry['cell'][$v] = str_replace('|'.$row[$v],'',$ov);
								break;
							}
						}
					}
					
					if($_data_filed['filed_type']=='lang'){
						$entry['cell']['lang'] = $row['lang'];
					}
					
					if($_data_filed['filed_type']=='cate'){
						$entry['cell']['cateid'] = get_cate_name($row['cateid'],$row['lang']);
					}
					
					if(empty($entry['cell'][$v])){
						$entry['cell'][$v] = $row[$v];
					}
				}
				
				$jsonData['rows'][] = $entry;
			}
			
			
			$this->ajaxReturn($jsonData,'JSON');
		}else{
			$module_id = $this->_module_id;
			//查询模型信息
			$Module = M('Module');
			$data   = $Module->find($module_id);
			$name    = $data['module_name'];
			$module_name = $name;
			$pid    = $data['module_pid'];
			$type    = $data['module_type'];
			$Module_title = json_decode($data['title'],true);
			$Module_title = $Module_title[$this->_lang];
	
			if($type == 2 && $pid){				
				$parent_data    = $Module->find($pid);
				$parent_name    = $parent_data['module_name'];
				$module_name = $parent_name;
				$parent_title   = json_decode($parent_data['title'],true);
				$parent_title   = $parent_title[$this->_lang];
			}
			
			//组装面包屑导航
			if($type == 2 && $pid){
				$position = '<a href="?s=/'.ucfirst($parent_name).'/index/module_id/'.$pid.'">'.L('cfg_list_itf_prefix_manage').$parent_title.'</a>';
				$position .= ' <span class="icon-angle-right"></span> '.'<a href="?s=/'.ucfirst($parent_name).'/index/module_id/'.$module_id.'">'.L('cfg_list_itf_prefix_manage').$Module_title.'</a>';
			}else{
				$position = '<a href="?s=/'.ucfirst($name).'/index/module_id/'.$module_id.'">'.L('cfg_list_itf_prefix_manage').$Module_title.'</a>';
			}
			
			//只看
			if($type==2&&$pid){
				$data_mlist = $Module->where('module_pid='.$pid)->select();
			}else{
				$data_mlist = $Module->where('module_pid='.$module_id)->select();
			}
			$justsee = '';
			$justsee .= '<div class="btn-group">';
			$justsee .= '<a data-toggle="dropdown" href="#" class="btn">';
			$justsee .= L('cfg_module_justsee');
			$justsee .= '<i class="icon-angle-down"></i>';
			$justsee .= '</a>';
			$justsee .= '<ul class="dropdown-menu">';
			foreach($data_mlist as $k=>$v){
				$now_title = json_decode($v['title'],true);
				$now_title = $now_title[$this->_lang];
				$justsee .= '<li><a href="?s=/'.ucfirst($module_name).'/index/module_id/'.$v['id'].'">'.$now_title.'</a></li>';
			}
			$justsee .= '</ul>';
			$justsee .= '</div>';
			
			
			$Module = M('Module');
			$data = $Module->where('module_name="'.strtolower(MODULE_NAME).'"')->find();
			$list_attr = json_decode($data['list_attr'],true);
			$lang = getLang();
			$lang_filter = C('LANG_ARRAY');
			
			$toolbar = '';
			foreach($list_attr['toolbar'] as $k=>$v){
				if($v == 'add'){
					$toolbar .= '<a href="__URL__/add/module_id/'.$module_id.'" class="btn green"><i class="icon-plus"></i> '.L('cfg_list_itf_btn_add').'</a>';
				}
				if($v == 'pdel'){
					$toolbar .= '<a class="btn red" id="batchDelete"><i class="icon-remove"></i>'.L('cfg_list_itf_btn_deletes').'</a>';
				}
			}
			
			$have_search = '';
			if($list_attr['have_search']==1){
				$have_search .= '<div class="dataTables_filter" id="userList_filter">';
				$have_search .= '<label>';
				$have_search .= '<input type="text" class="m-wrap medium" name="keywords" placeholder="'.L('cfg_list_itf_search_tis').'" />';
				$have_search .= '<button id="btn_search" class="btn black">';
				$have_search .= L('cfg_list_itf_search').' <i class="icon-search"></i>';
				$have_search .= '</button>';
				$have_search .= '</label>';
				$have_search .= '</div>';
			}
			
			$have_lang = '';
			if($list_attr['have_lang']==1){
				$have_lang .= '<div class="btn-group"><a class="btn red" title="" href="javascript:;">All</a>';
				foreach($lang_filter as $k=>$v){
					$have_lang .= '<a class="btn" title="'.$k.'" href="javascript:;">'.$v.'</a>';
				}
				$have_lang .= '</div>';
			}
			
			$listParam['listId'] = 'contentList';
			$listParam['jsonUrl'] = '__URL__/index/module_id/'.$module_id;
			$listParam['where'] = '';
			$listParam['pageNum'] = trim($list_attr['pageno'])?'10':$list_attr['pageno'];
			$listParam['nowPage'] = '1';
			$listParam['orderName'] = 'addtime';
			$listParam['orderDirection'] = 'desc';
			
			//复选框
			$listParam['colModel'][0]['display'] = 'checkbox';
			$listParam['colModel'][0]['name'] = 'id';
			$listParam['colModel'][0]['ordertable'] = false;	
			$listParam['colModel'][0]['myclass'] = 'center';
			$i = 1;
			foreach($list_attr['colModel']['name'] as $k=>$v){
				$listParam['colModel'][$i]['display'] = $list_attr['colModel']['display'][$this->_lang][$k];
				$listParam['colModel'][$i]['name'] = $v;
				if($list_attr['colModel']['ordertable'][$k]=='1'){
					$listParam['colModel'][$i]['ordertable'] = true;
				}else{
					$listParam['colModel'][$i]['ordertable'] = false;
				}			
				$listParam['colModel'][$i]['myclass'] = $list_attr['colModel']['myclass'][$k];
				
				$i++;
			}
			
			//时间
			$listParam['colModel'][$i]['display'] = L('cfg_form_ele_addtime');
			$listParam['colModel'][$i]['name'] = 'addtime';
			$listParam['colModel'][$i]['ordertable'] = true;	
			$listParam['colModel'][$i]['myclass'] = 'center';
			$i++;
			//时间
			$listParam['colModel'][$i]['display'] = L('cfg_form_ele_opreate');
			$listParam['colModel'][$i]['name'] = 'deal';
			$listParam['colModel'][$i]['ordertable'] = false;	
			$listParam['colModel'][$i]['myclass'] = 'center';
			
			if($list_attr['have_lang']==1){
				$listParam['getSearch'] = "function(where){var keywords = $('input[name=\"keywords\"]').val();if($.trim(keywords)==''){return false;}listParam.where = ' AND (";
				
				foreach($list_attr['colModel']['name'] as $k=>$v){
					$listParam['getSearch'] .= "`".$v."` LIKE \"%'+keywords+'%\" AND ";
				}
				
				$listParam['getSearch'] .= " lang=\"'+$('#lang_filter a.red').attr('title')+'\")';commonList.init(listParam);}";
			}
			
			$listParam = json_encode($listParam);
			
			$this->assign("toolbar",$toolbar);
			$this->assign("have_search",$have_search);
			$this->assign("have_lang",$have_lang);
			$this->assign("listParam",$listParam);
			$this->assign("position",$position);
			$this->assign("justsee",$justsee);
			$this->assign("Module_title",$Module_title);
			$this->display("Content:index");
		}
	}
	
	/**
	 * 公共添加方法
	 * @author tangbl
	 * @param  $table 表名
	 * @param  $imgae array("single"=>array("single"),"atlas"=>array("atlas"),"file"=>array("attach"))
	 * @param  $arr   额外的添加参数
	**/ 
    protected function content_add($table,$image=NULL,$arr=NULL){
        $t = D("$table");
        if($t->create()){
			$solevar = $t->solevar;
			if(is_array($image)){
				$single = $image['single'];
				if(is_array($single)){
					foreach($single as $v){
						add_edit_thumb($v, $solevar, $table);//添加缩略图
					}	
				}
				$atlas = $image['atlas'];
				if(is_array($atlas)){
					foreach($atlas as $v){
						add_edit_album($v, $solevar, $table);//添加图集
					}	
				}
				$attach = $image['attach'];
				if(is_array($attach)){
					foreach($attach as $v){
						add_edit_file($v, $solevar, $table);//添加文件
					}
				}
			}
			
            if(is_array($arr)){
               foreach($arr as $k=>$v){
                $t->$k=$v;
               }
            }
            
            $result = $t->add();
            /* $this->assign("jumpUrl",U($table.'/index'));
            $this->success(L('cfg_form_tipmsg_addsucc')); */
        }else{
            $this->error($t->getError());
        }
    }
    
    /**
     * 公共添加方法
     * @author tangbl
     * @param  $table 表名
     * @param  $imgae array("single"=>array("single"),"atlas"=>array("atlas"),"file"=>array("attach"))
     * @param  $arr   额外的添加参数
     **/
    protected function content_edit($table,$image=NULL,$arr=NULL){
    	$t = D("$table");
    	if($t->create()){
    		$t->id   = $arr["id"];
    		$solevar = $t->solevar;
    		if(is_array($image)){
    			$single = $image['single'];
    			if(is_array($single)){
    				foreach($single as $v){
    					add_edit_thumb($v, $solevar, $table);//添加缩略图
    				}
    			}
    			$atlas = $image['atlas'];
    			if(is_array($atlas)){
    				foreach($atlas as $v){
    					add_edit_album($v, $solevar, $table);//添加图集
    				}
    			}
    			$attach = $image['attach'];
    			if(is_array($attach)){
    				foreach($attach as $v){
    					add_edit_file($v, $solevar, $table);//添加文件
    				}
    			}
    		}
    			
    		if(is_array($arr)){
    			foreach($arr as $k=>$v){
    				$t->$k=$v;
    			}
    		}
    
    		$result = $t->save();
    		/* $this->assign("jumpUrl",U($table.'/index'));
    		$this->success(L('cfg_form_tipmsg_editsucc')); */
    	}else{
    		$this->error($t->getError());
    	}
    }
}